# String Quoting
Clear-Host
"This is a string"
'This is a string too!'

# Mixed quoted
'I just wanted to say "Hello World", Ok?'
"I can't believe how cool Powershell is!"

# Escape Sequences - use the backtick
Clear-Host
# backspace `b
"Power`bShell"

# newline `n
"Power`nShell"

# crlf `r`n
"Power`r`nShell"

# tabs
"Power`tShell"

# Here Strings - for large blocks of text
Clear-Host
$heretext=@"
Some text here
Some more here
	a bit more

a blank line above
"@

$heretext

$sql=@'
SELECT col1
	 , col2
	 , col3
	FROM someTable
	WHERE col1='a value'
'@

# String Interpolation
Set-Location C:\Code
Clear-Host

# Take the output of Get-ChildItem, which is an object, and gets that object
$items=(Get-ChildItem).Count
$loc=Get-Location

# Use these variables in a string
"There are $items items are in the folder $loc."

# To actually display the variable, escape it with a backtick
"There are `$items items are in the folder `$loc."

# String interpolation only works with double quotes
'There are $items items are in the folder $loc'

# Can use expressions in strings, need to be wrapped in $()
Clear-Host
"There are $((Get-ChildItem).Count) items are in the folder $(Get-Location)"

"Today is $(Get-Date). Be well."

"The 15% tip of 33.33 dollar bill is $(33.33*0.15) dollars"

# String Formatting 
[string]::Format("There are {0} items.",$items)

#Powershell shortcut
"There are {0} items." -f $items

"There are {0} items in the location {1}." -f $items,$loc

"There are {0} items in the location {1}. Wow, {0} is a lot of items!" -f $items,$loc

# Predefined formats
# N - Number
"N0 {0:N0} formatted" -f 12345678.119    # N0 12,345,678 formatted
"N1 {0:N1} formatted" -f 12345678.119    # N1 12,345,678.1 formatted
"N2 {0:N2} formatted" -f 12345678.119    # N2 12,345,678.12 formatted
"N2 {0:N9} formatted" -f 12345678.119    # N2 12,345,678.12 formatted
"N0 {0:N0} formatted"   -f 123.119       # N0 123 formatted
"N0 {0,8:N0} formatted" -f 123.119       # N0      123 formatted

# C - Currency
"C0 {0:C0} formatted" -f 12345678.1234   # C0 $12,345,678 formatted
"C1 {0:C1} formatted" -f 12345678.1234   # C1 $12,345,678.1 formatted
"C2 {0:C2} formatted" -f 12345678.1234   # C2 $12,345,678.12 formatted

# P - Percentage
"P0 {0:P0} formatted" -f 0.1234          # P0 12 % formatted
"P2 {0:P2} formatted" -f 0.1234          # P2 12.34 % formatted

# X - Hex
"X0 0x{0:X0} formatted" -f 1234          # X0 0x4D2 formatted
"X0 0x{0:X0} formatted" -f 0x4D2         # X0 0x4D2 formatted

# D - Decimal
"D0 {0:D0} formatted"   -f 12345678      # D0 12345678 formatted
"D8 {0:D8} formatted"   -f 123           # D8 00000123 formatted
"D0 {0:D0} formatted"   -f 123           # D0      123 formatted
"D0 {0,8:D0} formatted" -f 123           # D0      123 formatted

# Note, decimal only supports ints. This causes an error:
"D0 {0:D0} formatted"   -f 123.1         


# Custom formatting
$items = 1234
"There are {0:#,#0} items." -f $items    # There are 1,234 items.
  
"Custom 0, 25 $#,##0.0000  = {0,25:$ #,##0.0000} " -f 123456789.012000005   # Custom 0, 25 $#,##0.0000  =        $ 123,456,789.0120
"Custom 0, 25 $#,##0.0000  = {0,25:$ #,##0.00} "   -f 123456789.012000005   # Custom 0, 25 $#,##0.0000  =          $ 123,456,789.01
"Custom 0, 25 $#,##0.0000  = {0,25:$ #,##0.00} "   -f 123456789.012000005   # Custom 0, 25 $#,##0.0000  =          $ 123,456,789.01
                                                                            
"Custom 0, 10 #,##0%    = {0,10:#,##0%} "    -f 0.125                       # Custom 0, 10 #,##0%    =        13%
"Custom 0, 10 #,##0.00% = {0,10:#,##0.00%} " -f 0.125                       # Custom 0, 10 #,##0.00% =     12.50%
                                                                            
# Custom date formatting. Note MM is Month, mm is minute                              
"Today is {0:M/d/yyyy}. Be well."               -f $(Get-Date)              # Today is 3/13/2014. Be well.
"Today is {0,10:MM/dd/yyyy}. Be well."          -f $(Get-Date)              # Today is 03/13/2014. Be well.
"Today is {0,10:yyyyMMdd}. Be well."            -f $(Get-Date)              # Today is   20140313. Be well.
"Today is {0,10:MM/dd/yyyy hh:mm:ss}. Be well." -f $(Get-Date)              # Today is 03/13/2014 12:21:19. Be well.
                                                                            
# Calculations can be passed in as the item to be formatted                 
"The 20% tip of a 33.33 dollar bill is {0} dollars" -f (33.33 * 0.20)       # The 20% tip of a 33.33 dollar bill is 6.666 dollars

"The 20% tip of a 33.33 dollar bill is {0:0.00} dollars" -f (33.33 * 0.20)  # The 20% tip of a 33.33 dollar bill is 6.67 dollars

##









# String operators -like and -match

# Wildcards
Clear-Host
"PowerShell" -like "Power*"
"PowerShell" -like "arcane*"
"PowerShell" -like "?owerShell"  # question marks work for single characters
"PowerShell" -like "Power*[s-v]" # ends in a char between s and v
"PowerShell" -like "Power*[a-c]" # ends in a char between a and c

# Regular Expressions
Clear-Host
"888-368-1240" -match "[0-9]{3}-[0-9]{3}-[0-9]{4}"  
"ZZZ-368-1240" -match "[0-9]{3}-[0-9]{3}-[0-9]{4}"  
"888.368.1240" -match "[0-9]{3}-[0-9]{3}-[0-9]{4}"  

##

# Arrays
Clear-Host
$array="Arcane","Code"
$array
$array[0]
$array[1]
$array.GetType()

$array="Robert","Cain"
$array

$array[0]="Power"
$array[1]="Shell"
$array

# Formal Array Creation Syntax
$array=@("Power","Shell")
$array
$array=@()
$array.Count

$array+="Arcane"
$array+="Code"
$array.Count

$array=1..5
$array

$number=1,42,256
$number -contains 42
$number -contains 99
$number -notcontains 42

#Hash tables
$hash=@{"Key"="Value";
		"PowerShell"="PowerShell.com";
		"Arcane Code"="arcanecode.com"
		}

$hash
$hash["PowerShell"]
$hash."Arcane Code"

# you can use variables as keys
$myKey="PowerShell"
$hash.$myKey
$hash.$($myKey)
$hash.$("Power"+"Shell")

# Adding and removing values
$hash
$hash["Pluralsight"]="pluralsight.com"
$hash

$hash.Remove("Arcane Code")
$hash

# See if key exists
$hash.Contains("Pluralsight")
$hash.Contains("Arcane Code")


# See if value exists
$hash.ContainsValue("PowerShell.com")
$hash.ContainsValue("arcanecode.com")

# List keys and values
$hash.Keys
$hash.Values

$hash.Keys -contains "PowerShell"
$hash.Values -contains "PowerShell.com"


